package com.xiaoxin.yixinai.userinfo;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaoxin.yixinai._frame.base.BaseController;
import com.xiaoxin.yixinai._frame.base.Constant;
import com.xiaoxin.yixinai._frame.utils.MD5;
import com.xiaoxin.yixinai._frame.utils.StringUtils;
import com.xiaoxin.yixinai._frame.utils.Tools;

@Controller
@RequestMapping("/userinfo")
public class UserInfoController extends BaseController {
	
	@Resource
	private UserInfoService userInfoService;
	
	/**
	 * 验证登录名唯一
	 * @param userId 主键
	 * @param loginName  登录名
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/verifyLoginNameUnique", method=RequestMethod.POST)
	public Object verifyLoginNameUnique(Integer userId, @RequestParam(defaultValue="") String loginName) {
		if (StringUtils.isEmpty(loginName)) {
			return ERROR("empty");
		} else {
			UserInfo oldUserInfo = userInfoService.verifyLoginNameUnique(userId, loginName.trim());
			
			if (oldUserInfo == null) {
				return SUCCESS();
			} else {
				return ERROR("repeat");
			}
		}
	}
	
}
